/*
 * Created on Jan 22, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.client.module;


import java.util.Vector;
import java.util.Iterator;
import java.util.Collection;

import org.vectrics.VectricsException;

/**
 * @author mmoore
 */
abstract public class Module  {

	private Vector children = new Vector();
	private ModulePanel mainComponent = null;
	private NavigationPanel navigationPanel;
	
	abstract protected ModulePanel createMainPanel();
	abstract protected NavigationPanel createNavigationPanel();
	abstract public String getName();
	
	public Module() {
		super();
	}
	
	abstract protected void onActivate();
	
	public void addChild(Module module) {
		children.add(module);
	}
	
	public Collection getChildren() {
		return(children);
	}
	
	public final ModulePanel getMainPanel() {
		if (mainComponent == null) {
			mainComponent = createMainPanel();
		}
		return(mainComponent);
	}
	
	public final NavigationPanel getNavigationPanel() {
		if (navigationPanel == null) {
			navigationPanel = createNavigationPanel();
		}
		return(navigationPanel);
	}
	
	public String toString() {
		return(getName());	
	}
	
	public Module findModuleChild(Class moduleClass) {
		Iterator iter = children.iterator();
		Module foundModule = null;
		while ((foundModule == null) && (iter.hasNext())) {
			Module currentModule = (Module)iter.next();
			
			if (currentModule.getClass().equals(moduleClass)) {
				foundModule = currentModule;
			}
			else {
				foundModule = findModuleChild(moduleClass);
			}
		}
		return(foundModule);
	}
	
}
